package de.traveltainment.concept.envers.repository;

import de.traveltainment.concept.envers.database.Constants;
import de.traveltainment.concept.envers.entities.ChangeType;
import de.traveltainment.concept.envers.entities.Provider;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import java.util.Calendar;
import java.util.List;

/**
* Created by borlis on 13.06.2014.
*/
@RequestScoped
public class ProviderRepository {

    @Inject
    private EntityManager em;

    public Provider create(Provider t) {
        em.getTransaction().begin();
        t.setChangedBy(Constants.SYSTEM_USER);
        t.setChangedOn(Calendar.getInstance().getTime());
        t.setChangedType(ChangeType.I);
        t.setLocked(Constants.UNLOCKED);
        em.persist(t);
        em.getTransaction().commit();
        return t;
    }

    public void crealeCollection(List<Provider> providerList){
        em.getTransaction().begin();
        for(Provider provider: providerList){
            em.persist(provider);
        }
        em.getTransaction().commit();
    }

}
